local skill = fk.CreateSkill{
  name = "iberia__xiaoguo"
}

Fk:loadTranslationTable{
  [skill.name] = "骁果",
  [":"..skill.name] = "出牌阶段开始时，你可以令一名其他角色将两张手牌当【杀】对你使用或弃置，然后你也可以对其如此做。",
  [skill.name.."-prompt"] = "骁果：可以令一名其他角色将两张手牌当【杀】对你使用或弃置，然后你也可以对其如此做",
  [skill.name.."-reverse"] = "骁果：是否对 %src 也如此做（将两张手牌当【杀】对 %src 使用或弃置）？",
}

skill:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skill.name) and player == target and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askToChoosePlayers(player, {
      targets = table.filter(player.room:getOtherPlayers(player), function(p) return p:getHandcardNum() >= 2 end),
      max_num = 1, min_num = 1, skill_name = skill.name, cancelable = true, prompt = skill.name.."-prompt"
    })
    if #tos == 0 then return false end
    event:setCostData(self, tos)
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self) ---@type ServerPlayer[]

    ---@param from ServerPlayer
    ---@param to ServerPlayer
    ---@param cancelable boolean
    local function doEffect(from, to, cancelable)
      local ivk, ret = room:askToUseActiveSkill(from, {
        skill_name = "iberia__viewas",
        cancelable = cancelable, extra_data = {to = to.id},
        no_indicate = true
      })
      if ret and ret.cards and ret.interaction then
        if ret.interaction == "slash" then
          local slash = Fk:cloneCard("slash")
          slash:addSubcards(ret.cards)
          slash.skillName = skill.name
          room:useCard{
            card = slash,
            from = from,
            tos = ret.targets,
          }
        else
          room:throwCard(ret.cards, skill.name, from, from)
        end
      end
      if not cancelable and not ivk then
        room:throwCard(table.random(from:getCardIds("h"), 2), skill.name, from, from)
      end
    end

    doEffect(tos[1], player, false)
    if player:isAlive() then
      doEffect(player, tos[1], true)
    end
  end
})

return skill
